<!-- 隐患详情 -->
<template>
  <div class="warn-detail animate__animated animate__zoomIn">
    <div v-if="!loadingFlag" class="warn-detail-top">
      <dv-decoration-11 style="width: 30%; height: 50%; font-size: 0.3rem"
        >隐患综合信息</dv-decoration-11
      >
      <div class="goback">
        <GoBack></GoBack>
      </div>
      <div class="goindex">
        <GoIndex></GoIndex>
      </div>
    </div>
    <div v-if="!loadingFlag" class="useReg-main">
      <ul>
        <div class="box box1">
          <li v-for="(item, i) in head1" :key="i">
            <div class="li-box">
              <p>
                <span>{{ item.name }}</span>
              </p>
              <p>
                <span
                  v-if="item.prop == 'unit'"
                  class="link-blue"
                  @click="toUnitDetail"
                  >XXXX单位</span
                >
                <span v-else>{{ warnDatas[item.prop] }}</span>
              </p>
            </div>
          </li>
        </div>
      </ul>
    </div>
    <!-- loading -->
    <div v-if="loadingFlag" class="e-loading">
      <dv-loading style="color: #fff; opcity: 0.5"
        >数据加载中...</dv-loading
      >
    </div>
  </div>
</template>

<script>
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      loadingFlag: true,
      head1: [
        // { name: "处置措施", prop: "p1" },
        { name: "单位名称", prop: "p1" },
        { name: "单位地址", prop: "p2" },
        { name: "隐患级别", prop: "p3" },
        { name: "监察人员", prop: "p4" },
        { name: "受检单位的意见", prop: "p5" },
        { name: "整改时间", prop: "p5" },
        { name: "隐患内容", prop: "p6" },
        { name: "被检查单位", prop: "p7" },
      ],

      warnDatas: {
        p1: "-",
        p2: "-",
        p3: "-",
        p4: "-",
        p5: "-",
        p6: "-",
        p7: "-",
      },
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    toUnitDetail() {
      this.$router.push("/companyList-detail");
    },
    async init() {
      let type = this.$store.getters.getListCategory;
      let id = this.$route.params.id;
      let params = {};
      let ret = {};

      if (type == "postGetHiddenList") {
        console.log("从隐患列表过来, id:" + id);

        params = { hiddenId: id };
        let arr = await this.$http["postGetHiddenDetails"](params);
        if (arr.data.errorCode != 0) {
          return console.log("后台异常");
        }
        ret = arr.data.data;
      } else {
        console.log("监察任务或其他, id:" + id);

        params = { tasksId: id };
        let arr = await this.$http["postFindtaskDetails"](params);
        if (arr.data.errorCode != 0) {
          return console.log("后台异常");
        }
        ret = arr.data.data;
      }

      // return console.log(arr);
      this.warnDatas = {
        p1: ret.disposalMeasures || "--",
        p2: ret.address || "--",
        p3: ret.level || "--",
        p4: ret.userName || "--",
        p5: ret.unitOpinion || "--",
        p6: ret.content || "--",
        p7: ret.comName || "--",
      };

      this.loadingFlag = false
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.init();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  beforeRouteEnter(to,form,next) {
    if (JSON.stringify(to.params)=="{}") {
      to.meta.isBack = true
    }else{
      to.meta.isBack = false
    }
    next()
  },
  activated() {
    if (!this.$route.meta.isBack) {
      console.log('需要刷新');
      this.init()
    }else{
      console.log('缓存页面');
    }
  },
};
</script>

<style lang="less" scoped>
.warn-detail {
  width: 100%;
  height: 100%;
  .warn-detail-top {
    width: 100%;
    height: 15%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    color: @FontColor;
    .goback {
      position: absolute;
      left: 0;
      top: 2%;
    }
  }
  .useReg-main {
    width: 100%;
    height: 85%;
    ul {
      width: 70%;
      height: 100%;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      .box {
        display: flex;
        flex-wrap: wrap;
        background-color: rgba(245, 245, 245, 0.8);
        border-radius: 0.05rem;
        margin: 0.6% 0;
        li {
          width: 50%;
          height: 20%;
          display: flex;
          justify-content: center;
          align-items: center;
          .li-box {
            width: 90%;
            height: 80%;
            display: flex;
            border-radius: 0.04rem;
            overflow: hidden;
            p {
              width: 30%;
              height: 100%;
              display: flex;
              justify-content: center;
              align-items: center;
              // background-color: rgba(77, 144, 254, 0.5);
              span {
                font-size: 0.2rem;
                color: @Blue;
                font-weight: 700;
              }
            }
            p:last-child {
              width: 70%;
              span {
                color: #555;
              }
              // background-color: rgba(128, 195, 66, 0.7);
            }
          }
        }
      }
      .box1 {
        flex: 5;
        li {
          height: 20%;
        }
      }
      .box2 {
        flex: 4;
        //   background-color: rgba(77, 144, 254, 0.2);
        li {
          height: 25%;
        }
      }
      .box3 {
        flex: 2;
        li {
          height: 50%;
        }
      }
      .box4 {
        flex: 2;
        //   background-color: rgba(77, 144, 254, 0.2);
        li {
          height: 50%;
        }
      }
    }
  }
}
</style>